import 'dart:async';
import 'dart:convert' show utf8, json;
import 'dart:io';
import '../config.dart';


class RequestData {


  Future<String> baseRequest(String domain,String path,String type,{Map<String,String> params}) async {
    var httpClient = new HttpClient();
    var uri = new Uri.http(domain,path,params);
    String responseBody;
    switch (type){
      case "get":
        var request = await httpClient.getUrl(uri);
        var response = await request.close();
        responseBody = await response.transform(utf8.decoder).join();
        break;
      case "post":
        var request = await httpClient.postUrl(uri);
        var response = await request.close();
        responseBody = await response.transform(utf8.decoder).join();
        break;
      case "put":
        var request = await httpClient.putUrl(uri);
        var response = await request.close();
        responseBody = await response.transform(utf8.decoder).join();
        break;
      case "delete":
        var request = await httpClient.deleteUrl(uri);
        var response = await request.close();
        responseBody = await response.transform(utf8.decoder).join();
        break;
    }
    return responseBody;
  }

  void getBookByIds(){
    Map<String,String> params;


    Future<String> response = baseRequest("zxshuo.win", "/api/book/2", "get",params: params);

  }

  void getBookByid(){

  }

  void getChapter(){

  }






}